#ifndef BMPFILE_H_INCLUDED
#define BMPFILE_H_INCLUDED

typedef unsigned int	u32;
typedef unsigned short	u16;
typedef signed int		s32;
typedef unsigned char	u8;

class BMPFile {
private:
	struct BMPINFOHEADER {
		u16	signature;
		u32	sizeOfBMPFile;
		u16	reserved1;
		u16 reserved2;
		u32	startOfImage;	///< in bytes
		u32 sizeofBITMAPINFOHEADER;	///< must be 40
		u32 imageWidth;		///< in pixel
		u32 imageHeight;	///< in pixel
		u16	numberOfPlanes;	///< must be 1
		u16 bitsPerPixel; 	///< 1, 4, 8 or 24
		u32 compressionType;	///< 0 is none, 1 is RLE-9 2 is RLE-4
		u32 sizeOfImage;	///< in bytes
		u32 horizontalResolution;	///< in pixels per meter
		u32 verticalResolution;		///< in pixels per meter
		u32	numberOfColours;
		u32	numberOfImportantColors;
	} __attribute__((__packed__));

public:
	struct ImageInfo {
		u32	w;
		u32	h;
		u32 pitch;	// bytes of a line
		u32	bpp; ///< bits per pixel
	};

	BMPFile();
	~BMPFile();
	/*
	 * @param filename
	 * @retval 
	 */
	bool 	Init(const char *filename);

	bool	GetImageInfo(ImageInfo &imageInfo) const;

	bool	ReadScanline(u8 *dst, u32 dstPitch, u32 numberOfLines);

private:
	ImageInfo	m_imageInfo;
	u32			m_currentLine;

	u32			m_startOfImage;
	FILE		*m_fp;
};

#endif // BMPFILE_H_INCLUDED
